package cn.csg.iotplatform.module.system.service.eqfile;


import cn.csg.iotplatform.module.system.dal.dataobject.dvattachment.DvAttachmentDO;
import cn.csg.iotplatform.module.system.dal.mysql.dvattachment.DvAttachmentMapper;
import cn.csg.iotplatform.module.system.enums.AttachmentTypeEnum;
import com.alibaba.excel.util.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 物联备份附件 Service 实现类
 *
 * @author 系统管理员
 */
@Service
@Validated
public class DvAttachmentServiceImpl implements DvAttachmentService {

    @Resource
    private DvAttachmentMapper attachmentMapper;

    @Override
    public void syncWlFile(String flagId, String jobTypeCode, String url, Map<String,Object> map, Integer type) {
        DvAttachmentDO attachmentDO = new DvAttachmentDO();
        attachmentDO.setJobTypeCode(jobTypeCode);
        attachmentDO.setAttachmentFullPath(url);
        attachmentDO.setFlagId(flagId);
        attachmentDO.setIsSync(type);
        if(jobTypeCode.equals(AttachmentTypeEnum.certificatesImage.name())) {
            attachmentDO.setCertificatesType(map.get("certificate") != null && StringUtils.isNotBlank(map.get("certificate").toString())?
                    map.get("certificate").toString() : null);
            attachmentDO.setCertificatesLevel(map.get("levelOrType") != null && StringUtils.isNotBlank(map.get("levelOrType").toString()) ?
                    Integer.parseInt(map.get("levelOrType").toString()) : null);
            attachmentDO.setCertificatesCode(map.get("certificateNo") != null ?
                    map.get("certificateNo").toString() : null);
        }
        attachmentMapper.insert(attachmentDO);
    }
}